package com.lsa.letcode.the66.plusOne;

import static org.junit.Assert.assertArrayEquals;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.junit.Test;

public class PlusOneTest {

	@Test
	public void test() {
		Solution s = new Solution();
		for (int i = 0; i < 101; i++) {
			test(s, i);
		}
		
		test(s, 999888999);
	}

	private void test(Solution s, int n) {
		assertArrayEquals(toArray(n + 1), s.plusOne(toArray(n)));
	}
	
	private static int[] toArray(int n){
		List<Integer> l = new ArrayList<>();
		do{
			l.add(n % 10);
			n = n / 10; 
		}
		while(n != 0);
		Collections.reverse(l);
		
		int[] arr = new int[l.size()];
		for (int i = 0; i < l.size(); i++) {
			arr[i] = l.get(i);
		}
		return arr;
	}
}
